<?php

// Acceso restringido
defined('JL') or die('Acceso restringido');

class ActualiteBoxModel extends JLModelBase {

    /**
     * Insert ActualiteBox
     * @Retorna bool
     */
    public function insertActualiteBox($var_column, $int_id_actualite, $int_no_csme_actualite, $int_id_newsletter) {
        $_true = false;

        $sql = "INSERT INTO 
              `tbl_actualite_box`
            (
              `var_column`,
              `int_id_actualite`,
              `int_no_csme_actualite`,
              `int_id_newsletter`
            ) 
            VALUE (
              " . $this->DB->Quote($var_column) . ",
              " . $this->DB->Quote($int_id_actualite) . ",
              " . $this->DB->Quote($int_no_csme_actualite) . ",
              " . $this->DB->Quote($int_id_newsletter) . "
            )";

        $this->DB->executeQuery($sql);

        if ($this->DB->getRowsAffected() > 0) {
            $_true = $this->DB->getInsertedId();
        }

        return $_true;
    }

    /**
     * Get ActualiteBox
     * @Retorna bool
     */
    public function getActualiteBoxByIdNewsletter($id) {
        $_true = null;

        $sql = "SELECT 
              tbl_actualite_box.id_actualite_box,
              tbl_actualite_box.var_column,
              tbl_actualites.var_ac_title,
              tbl_sections.var_desc_section,
              tbl_actualite_box.int_no_csme_actualite,
              tbl_actualite_box.int_order,
              tbl_actualites.int_id_section,
              tbl_actualite_box.int_id_actualite
            FROM
              tbl_actualites
              INNER JOIN tbl_actualite_box ON (tbl_actualites.int_actualite = tbl_actualite_box.int_id_actualite)
              INNER JOIN tbl_sections ON (tbl_actualites.int_id_section = tbl_sections.int_id_section )
            WHERE
              tbl_actualite_box.int_id_newsletter = " . $this->DB->Quote($id) . " 
            ORDER BY tbl_actualite_box.int_order DESC";

        $this->DB->executeQuery($sql);

        if ($this->DB->getRowsAffected() > 0) {
            $_true = $this->DB->getDataArray();
        }

        return $_true;
    }

    /**
     * update ActualiteBox
     * @Retorna bool
     */
    public function updateActualiteBox($id_actualite_box, $var_column, $int_order) {
        $_true = false;

        $sql = "UPDATE 
              `tbl_actualite_box`  
            SET 
              `var_column` = " . $this->DB->Quote($var_column) . ",
              `int_order`  = " . $this->DB->Quote($int_order) . "
            WHERE 
              `id_actualite_box` = " . $this->DB->Quote($id_actualite_box) . "";

        $this->DB->executeQuery($sql);

        if ($this->DB->getRowsAffected() > 0) {
            $_true = true;
        }

        return $_true;
    }

    /**
     * Elimina ActualiteBox
     * @Retorna bool
     */
    public function deleteActualiteBox($id) {
        $_true = false;

        $sql = "DELETE FROM 
              `tbl_actualite_box` 
            WHERE 
              `id_actualite_box` = " . $this->DB->Quote($id) . "";

        $this->DB->executeQuery($sql);

        if ($this->DB->getRowsAffected() > 0) {
            $_true = true;
        }

        return $_true;
    }

    /**
     * Elimina ActualiteBox
     * @Retorna bool
     */
    public function deleteActualiteBoxByIdNewsletter($id) {
        $_true = false;

        $sql = "DELETE FROM 
              `tbl_actualite_box` 
            WHERE 
              `int_id_newsletter` = " . $this->DB->Quote($id) . "";

        $this->DB->executeQuery($sql);

        if ($this->DB->getRowsAffected() > 0) {
            $_true = true;
        }

        return $_true;
    }

}